package com.gxa.controller;

import com.gxa.pojo.Operation;
import com.gxa.service.impl.OperationServiceImpl;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import org.apache.ibatis.annotations.Insert;

@RestController
@Api(tags = "操作管理")
public class OperationController {

    @Autowired
    private OperationServiceImpl operationService;


    @PostMapping("/operation")
    @ApiOperation("操作管理添加")
    @ResponseBody
    public ResponseData insertOperation(@RequestBody Operation operation) {

        if (operationService.insertOperation(operation)) {
            return new ResponseData(1, "添加成功");
        } else {
            return new ResponseData(0, "添加失败");
        }
    }
    /**
     * 添加数据
     *
     * @param operation 主键
     * @return 添加是否成功
     */

  /*  @Insert("/insert")
    public ResponseData insertOperation(Operation operation) {
        ResponseData responseData = new ResponseData();
        if (this.operationService.insertOperation(operation)){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }*/
    @GetMapping("/selectOperation")
    @ApiOperation(value = "操作管理查找",httpMethod = "POST")
    @ResponseBody
   /* public ResponseData selectOperation(Operation operation) {
        ResponseData responseData = new ResponseData();
        if (this.operationService.selectOperation(operation)) {
            responseData.setCode(404);
            responseData.setMsg("fail");
        } else {
            responseData.setCode(200);
            responseData.setMsg("success");
        }
        return responseData;
    }*/
    public ResponseData selectOperation(@ApiParam(value = "显示第几页",required = true) Integer pageNum, @ApiParam(value = "每页显示几条",required = true) Integer pageSize){

        if(operationService.selectOperation(pageNum,pageSize)!=null){
            return new ResponseData(1,"显示成功",operationService.selectOperation(pageNum,pageSize));
        }else {
            return new ResponseData(0,"显示失败");
        }
    }

    @DeleteMapping("/deleteOperation")
    @ApiOperation("操作管理信息删除")
    @ResponseBody
    public ResponseData deleteOperation(@ApiParam(value = "要删除的名字",required = true) String operation_type ){
        if(operationService.deleteOperation(operation_type)){
            return new ResponseData(1,"删除成功");
        }else {
            return new ResponseData(0,"删除失败");
        }
    }
}
